package com.physicscard2d.framework;

import com.physicscard2d.framework.common.TimeInfo;
import com.physicscard2d.framework.common.V2;
import com.physicscard2d.framework.common.V3;

public class PhysicsObjectMove3D implements IPhysicsObject {

	private final V3 position3D = new V3();
	private final V3 prevPosition3D = new V3();
	private final V2 position = new V2();
	
	private final V3 velocity3D = new V3();
	private final V2 velocity = new V2();
	
	private final V3 accelerate3D = new V3();
	private final V2 accelerate = new V2();
	
	@Override
	public void setPosition(float x, float y) {
		prevPosition3D.set(position3D);
		position3D.x = x;
		position3D.y = y;
	}

	public void setPositionZ(float z) {
		prevPosition3D.set(position3D);
		position3D.z = z;
	}
	
	public void setPosition(float x, float y, float z) {
		prevPosition3D.set(position3D);
		position3D.set(x, y, z);
	}
	
	public V3 getPosition3D() {
		return position3D;
	}
	
	public float getPositionZ() {
		return position3D.z;
	}
	
	public V3 getVelocity3D() {
		return velocity3D;
	}
	
	public float getVelocityZ() {
		return velocity3D.z;
	}
	
	public V3 getAccelerate3D() {
		return accelerate3D;
	}
	
	public float getAccelerateZ() {
		return accelerate3D.z;
	}
	
	@Override
	public V2 getPosition() {
		position.set(position3D.x, position3D.y);
		return position;
	}

	@Override
	public V2 getPrevPosition() {
		position.set(prevPosition3D.x, prevPosition3D.y);
		return position;
	}

	@Override
	public float getDamping() {
		return 0;
	}

	@Override
	public int getCollisionLevel() {
		return 0;
	}

	@Override
	public float move(TimeInfo time, V2 argV2) {
		final float argZ = velocity3D.z * time.ratio;
		argV2.set(velocity3D.x * time.ratio, velocity3D.y * time.ratio);
		
		prevPosition3D.set(position3D);
//		position.addLocal(argV2);
		position3D.x += argV2.x;
		position3D.y += argV2.y;
		position3D.z += argZ;
		return argZ;
	}

	@Override
	public void modifierPosition() {}

	@Override
	public void modifierPosition(V2 MTD) {
	}

	@Override
	public void updateVelocity(TimeInfo time) {
		this.velocity3D.x += this.accelerate3D.x * time.ratio;
		this.velocity3D.y += this.accelerate3D.y * time.ratio;
		this.velocity3D.z += this.accelerate3D.z * time.ratio;
	}

	@Override
	public void setVelocity(V2 velocity) {
		velocity3D.x = velocity.x;
		velocity3D.y = velocity.y;
	}

	@Override
	public void setVelocityX(float x) {
		velocity3D.x = x;
	}

	@Override
	public void setVelocityY(float y) {
		velocity3D.y = y;
	}

	@Override
	public void setVelocity(float x, float y) {
		velocity3D.x = x;
		velocity3D.y = y;
	}

	@Override
	public void setAccelerate(V2 accelerate) {
		accelerate3D.x = accelerate.x;
		accelerate3D.y = accelerate.y;
	}

	@Override
	public void setAccelerateX(float x) {
		accelerate3D.x = x;
	}

	@Override
	public void setAccelerateY(float y) {
		accelerate3D.y = y;
	}

	@Override
	public void setAccelerate(float x, float y) {
		accelerate3D.x = x;
		accelerate3D.y = y;
	}

	@Override
	public V2 getVelocity() {
		velocity.set(velocity3D.x, velocity3D.y);
		return velocity;
	}

	@Override
	public V2 getAccelerate() {
		accelerate.set(accelerate3D.x, accelerate3D.y);
		return accelerate;
	}

	@Override
	public void setVelocityDamping(float damping) {
		
	}

	@Override
	public float getVelocityDamping() {
		return 0;
	}

	@Override
	public void initAdvance() {
		position3D.set(prevPosition3D);
	}

	@Override
	public void setVelocityZ(float z) {
		velocity3D.z = z;
	}

	@Override
	public void setAccelerateZ(float z) {
		accelerate3D.z = z;
	}

	@Override
	public void modifierPositionXZ(V2 MTD) {
		
	}
	
	@Override
	public V2 getPositionXZ(){
		position.set(position3D.x, position3D.z);
		return position;
	}

	@Override
	public void setCollisionLevel(int level) {
		
	}

}
